package com.xiao.train.business.controller.admin;

import ch.qos.logback.classic.Logger;
import com.xiao.train.business.service.TrainSeatService;
import com.xiao.train.business.service.TrainService;
import com.xiao.train.common.resp.CommonResp;
import com.xiao.train.business.req.TrainQueryReq;
import com.xiao.train.business.req.TrainSaveReq;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/train")
public class TrainAdminController {

    @Resource
    TrainService trainService;

    @Resource
    TrainSeatService trainSeatService;

    @PostMapping("save")
    public CommonResp save(@Valid @RequestBody TrainSaveReq req) {
        trainService.save(req);
        return new CommonResp();
    }

    @GetMapping("query-list")
    public CommonResp queryList(@Valid TrainQueryReq req) {
        return new CommonResp(trainService.queryList(req));
    }

    @GetMapping("query-all")
    public CommonResp queryAll() {
        return new CommonResp(trainService.queryAll());
    }

    @DeleteMapping("delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        trainService.delete(id);
        return new CommonResp();
    }

    @GetMapping("gen-seat/{trainCode}")
    public CommonResp genSeat(@PathVariable String trainCode) {
        trainSeatService.genTrainSeat(trainCode);
        return new CommonResp();
    }
}